
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class ViewAlbumForm extends List implements Runnable, CommandListener {

    private HomeScreen homeScreen;
    private Command cmdBack = new Command("Back", Command.BACK, 2);

    public ViewAlbumForm(HomeScreen homeScreen) {
        super("View Album", IMPLICIT);
        this.homeScreen = homeScreen;
        Common.Client.ViewListAlbum();
        new Thread(this).start();
        addCommand(cmdBack);
        setCommandListener(this);
    }

    public void run() {
        while (true) {
            if (Common.Client.albumList.size() > 0) {
                this.deleteAll();
                for (int i = 0; i < Common.Client.albumList.size() - 1; i++) {
                    append(Common.Client.albumList.elementAt(i).toString(), null);
                }
                Common.Client.albumList.removeAllElements();
                return;
            }
            System.gc();
        }
    }

    public void commandAction(Command c, Displayable d) {
        if (c == SELECT_COMMAND) {
            Common.Client.ViewListImageName(getSelectedIndex());
            homeScreen.DisplayListImageName();
        } else if (c==cmdBack){
            homeScreen.DisplayChoseViewAlbumForm();
        }
    }
}
